all:download build install

build:download
	mkdir -p $(DIR_WORK)
	$(MAKE) $@ -C$(DIR_WORK) -f$(DIR_ORIG)/Makefile DEF_PROJECT=$(DEF_PROJECT) PID=$(PID)
	touch -m $(DIR_WORK)/$(@F)

install:build
	mkdir -p $(DIR_WORK)
	$(MAKE) $@ -C$(DIR_WORK) -f$(DIR_ORIG)/Makefile DEF_PROJECT=$(DEF_PROJECT) PID=$(PID)

clean:
	mkdir -p $(DIR_WORK)
	$(MAKE) $@ -C$(DIR_WORK) -f$(DIR_ORIG)/Makefile DEF_PROJECT=$(DEF_PROJECT) PID=$(PID)

distclean:
	mkdir -p $(DIR_WORK)
	$(MAKE) $@ -C$(DIR_WORK) -f$(DIR_ORIG)/Makefile DEF_PROJECT=$(DEF_PROJECT) PID=$(PID)

mostlyclean:
	mkdir -p $(DIR_WORK)
	$(MAKE) $@ -C$(DIR_WORK) -f$(DIR_ORIG)/Makefile DEF_PROJECT=$(DEF_PROJECT) PID=$(PID)

maintainer-clean:
	mkdir -p $(DIR_WORK)
	$(MAKE) $@ -C$(DIR_WORK) -f$(DIR_ORIG)/Makefile DEF_PROJECT=$(DEF_PROJECT) PID=$(PID)

download:
	mkdir -p $(DIR_WORK)
	$(MAKE) $@ -C$(DIR_WORK) -f$(DIR_ORIG)/Makefile DEF_PROJECT=$(DEF_PROJECT) PID=$(PID)

depend:
	@echo -e 'deps+=$(fullname)' >$(DIR_BUILD)/$@/$(fullname).mk
	@echo -e '$(fullname):$(addsuffix $(addprefix -,$(group)),$(deps)) $(extdeps)' >>$(DIR_BUILD)/$@/$(fullname).mk
	@echo -e '$(fullname):DIR_WORK=$(DIR_WORK)' >>$(DIR_BUILD)/$@/$(fullname).mk
	@echo -e '$(fullname):DIR_ORIG=$(DIR_ORIG)' >>$(DIR_BUILD)/$@/$(fullname).mk
	@echo -e '$(fullname):DEF_PROJECT=$(DEF_PROJECT)' >>$(DIR_BUILD)/$@/$(fullname).mk
	$(if $(name),,@rm -f $(DIR_BUILD)/$@/$(fullname).mk)
	$(foreach i,$(subdir),$(if $(wildcard $i/Makefile),$(MAKE) $@ -C $i DEF_PROJECT=$(DEF_PROJECT)/.. ;exit 0 $_))
